#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1010;
int n, m;
int a[N][N],b[N],c[N];

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		b[i] = c[i] = i;
		for (int j = 1; j <= n; j++) {
			cin >> a[i][j];
		}
	}
	while (m--) {
		int op, x, y;
		cin >> op >> x >> y;
		if (op == 1) swap(b[x], b[y]);
		else if (op == 0) swap(c[x], c[y]);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cout << a[b[i]][c[j]] << " ";
		}
		cout << endl;
	}
	return 0;
}